package com.llxy.web.controller.worker;
import com.llxy.common.annotation.Log;
import com.llxy.common.core.controller.BaseController;
import com.llxy.common.core.domain.AjaxResult;
import com.llxy.common.core.page.TableDataInfo;
import com.llxy.common.enums.BusinessType;
import com.llxy.worker.domain.Homemaking;
import com.llxy.worker.service.HomemakingService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* (t_homemaking)表控制层
*
* @author 马瑞龙
*/
@RestController
@RequestMapping("/worker/homemaking")
public class HomemakingController extends BaseController {
    /**
    * 服务对象
    */
    @Autowired
    private HomemakingService homemakingService;

    /**
     * 获取家政列表
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:list')")
    @GetMapping("/list")
    public TableDataInfo list(Homemaking homemaking)
    {
        startPage();
        List<Homemaking> homemakingDTOList = homemakingService.selectHomemakingList(homemaking);
        return getDataTable(homemakingDTOList);
    }

    /**
     * 获取家政列表(不分页)
     */
    @GetMapping("/allList")
    public AjaxResult allList()
    {
        return success(homemakingService.selectHomemakingList(null));
    }
    /**
     * 新增家政
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:add')")
    @Log(title = "家政管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Homemaking homemaking)
    {
        return toAjax(homemakingService.insertSelective(homemaking));
    }

    /**
     * 修改家政
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:edit')")
    @Log(title = "家政管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Homemaking homemaking)
    {
        return toAjax(homemakingService.updateByPrimaryKeySelective(homemaking));
    }

    /**
     * 根据家政编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(homemakingService.selectByPrimaryKey(id));
    }

    /**
     * 删除家政
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:remove')")
    @Log(title = "家政管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {
        return toAjax(homemakingService.deleteByPrimaryKey(id));
    }

    /**
     * 查询家政下的护工
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:query')")
    @GetMapping(value = "/supportWorker/{id}")
    public TableDataInfo getSupportWorkerInfo(@PathVariable Integer id,
                                           String type)
    {
        startPage();
        return getDataTable(homemakingService.selectSupportWorkerInfo(id,type));
    }

    /**
     * 查询家政下的岗位
     */
    @PreAuthorize("@ss.hasPermi('worker:homemaking:query')")
    @GetMapping(value = "/job/{id}")
    public TableDataInfo getJobInfo(@PathVariable Integer id,
                                           String type)
    {
        startPage();
        return getDataTable(homemakingService.selectJobInfo(id,type));
    }

}
